import { getRouteList, testTokenLogin } from "@/service/api.js";
import { create } from "zustand";
export const useLogin = create((set) => ({
  routeList: [],
  loginStatus: false,
  setState: (payload) => {
    let obj = {};
    Object.keys(payload).forEach((key) => {
      obj[key] = payload[key];
    });
    set(obj);
  },
  fetchGetRouteList: async (params) => {
    const res = await getRouteList(params);
    if (res && res?.code === 200) {
      set({
        routeList: res?.data,
        loginStatus: true,
      });
      localStorage.setItem("token", JSON.stringify("sdfsdfklsfksjflsfkjkls"));
    } else {
      set({
        routeList: [],
        loginStatus: false,
      });
      localStorage.removeItem("token");
    }
    return res;
  },
  fetchTestTokenLogin: async () => {
    const res = await testTokenLogin();
    console.log(res, "双token登录信息");
  },
}));
